package com.emontis.notiztapete.components;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

@SuppressWarnings ("unused")
public class Layout
{
  @Property
  @Parameter (required = true, defaultPrefix = BindingConstants.LITERAL)
  private String title;

  // --[ Navigation ]-------------------------------------------------------------------------------

  @Property
  private String pageName;

  @Inject
  private ComponentResources resources;

  public String getClassForPageName ()
  {
    return this.resources.getPageName().equalsIgnoreCase(this.pageName) ? "current_page" : null;
  }

  public String[] getPageNames ()
  {
    return new String[] {"Index", "Notes/Add", "Notes/ShowInGrid"};
  }

  // --[ Head Content ]-----------------------------------------------------------------------------
  // All <head> content is overwritable in pages using this Component.

  @Parameter
  private Block head;

  @Component
  private Head defaultHeadContent;

  public Object getHeadContent ()
  {
    return this.head == null ? this.defaultHeadContent : this.head;
  }

  // --[ Additional Head Content ]------------------------------------------------------------------
  // Additional <head> content is specifiable in pages using this Component.

  @Parameter
  private Block additionalHead;

  @Component
  private Head defaultAdditionalHeadContent;

  public Object getAdditionalHeadContent ()
  {
    return this.additionalHead == null ? this.defaultAdditionalHeadContent : this.additionalHead;
  }

}
